namespace Hack.Decompiling.PEA.CLR
{
  using System;
  using System.Collections.Generic;
  using System.Text;
  using PEA.PE;

  public enum ImageFlags:uint
  {
    /// <summary>
    /// COM+ Header entry point flags(Always 1)
    /// </summary>
    ILONLY            = 0x00000001,
    /// <summary>
    /// Image may only be loaded into a 32-bit process, 
    /// for instance if there are 32-bit vtablefixups,
    /// or casts from native integers to int32. 
    /// CLI implementations that have 64 bit native integers 
    /// shall refuse loading binaries with this flag set.
    /// </summary>
    BIT32REQUIRED     = 0x00000002,
    IL_LIBRARY        = 0x00000004,
    /// <summary>
    /// Image has a strong name signature.
    /// </summary>
    STRONGNAMESIGNED  = 0x00000008,
    NATIVE_ENTRYPOINT = 0x00000010,
    /// <summary>
    /// (Always 0)
    /// </summary>
    TRACKDEBUGDATA    = 0x00010000,
  }

  public enum VTableType:ushort
  {
    BIT32 = 0x01,               // V-table slots are 32-bits in size.   
    BIT64 = 0x02,               // V-table slots are 64-bits in size.   
    FROM_UNMANAGED = 0x04,      // If set, transition from unmanaged.
    CALL_MOST_DERIVED = 0x10,   // Call most derived method described by
  }


  /// <summary>
  /// The CLI header contains all of the runtime-specific data entries and other information.  
  /// The header should be placed in a read only, sharable section of the image.  
  /// This header is defined as follows:
  /// </summary>
  public unsafe struct CLIHeader
  {
    /// <summary>
    /// Size of the header in bytes
    /// </summary>
    public UInt32 SizeOfHeader;
    /// <summary>
    /// The minimum version of the runtime required to run this program, currently 2.
    /// </summary>
    public UInt16 MajorRuntimeVersion;
    /// <summary>
    /// The minor portion of the version, currently 0.
    /// </summary>
    public UInt16 MinorRuntimeVersion;
    /// <summary>
    /// RVA of the physical meta data 
    /// </summary>
    public ImageDataDirectory MetaData;
    /// <summary>
    /// Flags describing this runtime image
    /// </summary>
    public UInt32 Flags;
    /// <summary>
    /// Token for the MethodDef or File of the entry point for the image
    /// </summary>
    /// <remarks>
    /// If COMIMAGE_FLAGS_NATIVE_ENTRYPOINT is not set, 
    /// EntryPointToken represents a managed entrypoint.
    /// If COMIMAGE_FLAGS_NATIVE_ENTRYPOINT is set, 
    /// EntryPointRVA represents an RVA to a native entrypoint.
    /// </remarks>
    public UInt32 EntryPointToken;
    /// <summary>
    /// Location of CLI resources
    /// </summary>
    public ImageDataDirectory Resources;
    /// <summary>
    /// RVA of the hash data for this PE file used by the CLI loader for binding and versioning
    /// </summary>
    public ImageDataDirectory StrongNameSignature;
    /// <summary>
    /// Always 0
    /// </summary>
    public ImageDataDirectory CodeManagerTable;
    /// <summary>
    /// RVA of an array of locations in the file 
    /// that contain an array of function pointers (e.g., vtable slots), see below.
    /// </summary>
    public ImageDataDirectory VTableFixups;
    /// <summary>
    /// Always 0
    /// </summary>
    public ImageDataDirectory ExportAddressTableJumps;
    /// <summary>
    /// Always 0
    /// </summary>
    public ImageDataDirectory ManagedNativeHeader;
  }
}
